#include <stdio.h>
#include <ctype.h>
#include <string.h>
char opword[]="+-*/=";
char bordword[]="()";
FILE *fin,*fout; 
int main()
{
	char ch,token[40];
	int es=0,j,state,brp;
	if((fin=fopen("I1.txt","r"))==NULL)
	{
		printf("\n打开词法分析输入文件出错!\n");
		return(1);
	}
	if((fout=fopen("O1.txt","w"))==NULL)
	{
		printf("\n创建词法分析输出文件出错!\n");
		return(2);
	}
	ch=getc(fin);
	while(ch!=EOF)
	{
		while(ch==' '||ch=='\n'||ch=='\t')
			ch=getc(fin);
		if(isalpha(ch)||ch=='_')
		{
			token[0]=ch;
			j=1;
			ch=getc(fin);
			while(isalnum(ch)||ch=='_')
			{
				token[j++]=ch;
				ch=getc(fin); 
			}
			token[j]='\0'; 
			fprintf(fout,"(%s,%s)\n","10",token); 
				
		}
		else if(isdigit(ch)||ch=='.')
		{
			j=0;
			state=0;
			brp=1;
			while(brp)
			{
				switch(state)
				{
				case 0:
					if(ch=='.')
					{
						token[j++]=ch;
						state=1;	
					}
					else if(isdigit(ch))
					{
						token[j++]=ch;
						state=6;
					}
					ch=getc(fin);
					break;
				case 1:
					if(isdigit(ch))
					{
						token[j++]=ch; 
						ch=getc(fin);
						state=2;
					}
					else brp=0;
					break;
				case 2:
					while(isdigit(ch))
					{
						token[j++]=ch; 
						ch=getc(fin);
					}
					if(ch=='E'||ch=='e')
					{
						token[j++]=ch; 
						ch=getc(fin);
						state=3;
					}
					else brp=0;
					break;
				case 3:
					if(ch=='+'||ch=='-')
					{
						token[j++]=ch; 
						state=4;
						ch=getc(fin);
					}
					else if(isdigit(ch))
					{
						token[j++]=ch; 
						state=5;
						ch=getc(fin);
					}
					else brp=0;
					break;
				case 4:
					if(isdigit(ch))
					{
						token[j++]=ch; 
						ch=getc(fin);
						state=5;
					}
					else brp=0;
					break;
				case 5:
					brp=0;
					break;
				case 6:
					while(isdigit(ch))
					{
						token[j++]=ch; 
						ch=getc(fin);
					}
					
					if(ch=='.')
					{
						token[j++]=ch; 
						ch=getc(fin);
						state=1;
					}
					else brp=0;
					break;
				//default:break;
				}
			}
			//printf("%d\n",state);
			token[j]='\0';
			if(state==6||state==5||state==2)
				fprintf(fout,"(%s,%s)\n","40",token);
		}
		else if(strchr(bordword,ch)>0)  
		{
			token[0]=ch;
			token[1]='\0';
			ch=getc(fin);
			fprintf(fout,"(%s,%s)\n","30",token); 
		}
		else if(strchr(opword,ch)>0)  
		{
			token[0]=ch;
			token[1]='\0';
			ch=getc(fin);
			fprintf(fout,"(%s,%s)\n","20",token); 
		}
		else
		{
			token[0]=ch;token[1]='\0';
			ch=getc(fin);
			es=3;
			fprintf(fout,"(%s,%s)\n","ERROR",token);
		}
	}
	fclose(fin);
	fclose(fout);
	printf("%d\n",es);
	return 0;
}